package game.view.panel.game
{//
	import com.greensock.TweenMax;
	
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.text.*;
	
	import game.model.GameData;
	import game.model.type.Enum;
	import game.view.base.gamepanel.LevelGoodsViewUI;
	
	import morn.App;
	import morn.core.components.*;
	import morn.core.handlers.Handler;
	public class LevelGoodsView extends LevelGoodsViewUI
	{
		private var myIndex:int=0;
		public function LevelGoodsView()
		{
			super();
		}
		override protected function initialize():void
		{
			super.initialize();
			var vo:Object=GameData.instance.levelGsXyList[myIndex];
			this.x=vo.x;this.y=vo.y;
			initData();
		}
		public function initData():void{
			var list:Array=GameData.instance.levelList;
			for(var i:int=0;i<list.length;i++){
				var box:Box=this['levelBox'+(i+1)];
				var moneyLabel:Label=box.getChildByName('moneyLabel') as Label;
				var holdNickLabel:Label=box.getChildByName('holdNick') as Label;
				var tonggImg:Image=box.getChildByName('tonggImg') as Image;
				var goodsImg:Image=box.getChildByName('goodsImg') as Image;
				var vo:Object=list[i];
				holdNickLabel.text='守关人：'+vo.holdNick;
				tonggImg.visible=false;
				if(vo.awardId==Enum.no_num){
					moneyLabel.text='';	
					goodsImg.visible=false;
				}else{
					moneyLabel.text=vo.awardName+'*'+vo.amount+'('+vo.awardMoney+'呱元)';
					goodsImg.visible=true;
					
				}
			}
		}
		/**
		 * 设置关卡 1-6
		 * isnow:true 马上完成
		 */
		public function setLevel(level:int,isnow:Boolean=false):void{
			
			level--;
			var vo:Object=GameData.instance.levelGsXyList[level];
			if(myIndex==level){
				mapComplete(vo);
				return;
			}
			if(isnow){
				mapComplete(vo);
				return;
			}
			GameData.instance.isMapMove=true;
			
			TweenMax.killChildTweensOf(this);
			var timeN:Number=0.5*(Math.abs(Math.floor(level-myIndex)));
			timeN=(timeN<0.5?0.5:timeN);
			trace(timeN,Math.floor(level-myIndex),level-myIndex,myIndex,level);
			TweenMax.to(this,timeN,{x:vo.x,y:vo.y,onComplete:mapComplete,onCompleteParams:[vo]});
			myIndex=level;
		}
		private function mapComplete(data:Object):void{
			TweenMax.killChildTweensOf(this);
			GameData.instance.isMapMove=false;
			this.x=data.x;
			this.y=data.y;
			(this.parent as GamePanel).levelComplete();
		}
	}
}